//
//  SISSHousingCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/14.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSHousingCell.h"


@interface SISSHousingCell ()
@property (weak, nonatomic) IBOutlet UIButton *recommendButton;

@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *markLabels;

@property (weak, nonatomic) IBOutlet UILabel *neighbourhoodAndPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaTypeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelsViewHeight;
@property (weak, nonatomic) IBOutlet UILabel *visibleLabel;


@end
@implementation SISSHousingCell




- (void)setHouseResourceModel:(SISSHouseResourceModel *)houseResourceModel {
    _houseResourceModel = houseResourceModel;
    
    self.neighbourhoodAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %@万",houseResourceModel.neighbourhood,houseResourceModel.price];
    
    self.regionAreaTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %@㎡ | %@",houseResourceModel.region,houseResourceModel.regionDetail,[PublicUtil returnTwoDeciTwoDecimalFormatter:houseResourceModel.area],houseResourceModel.houseType];
    
        
    UIColor *color = houseResourceModel.read == 1 ? COLOR(0x8998A5) : COLOR(0x334A60);
    self.neighbourhoodAndPriceLabel.textColor = color;
    self.regionAreaTypeLabel.textColor = color;

    
    if (houseResourceModel.listTag.count > 0) {
        self.labelsViewHeight.constant = 30;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    
    for (UILabel *label in self.markLabels) {
        
        label.hidden = YES;
    }
    
    for (int i = 0; i < houseResourceModel.listTag.count; i++) {
        UILabel *label = self.markLabels[i];
        if ([houseResourceModel.listTag[i].tag isEqualToString:@""]) continue;
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",houseResourceModel.listTag[i].tag];
        NSInteger colorIndex = houseResourceModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
   
}

- (void)setHouseCooperationModel:(SISSHouseCooperationModel *)houseCooperationModel {
    _houseCooperationModel = houseCooperationModel;
    
    self.neighbourhoodAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %@万",houseCooperationModel.neighbourhood,houseCooperationModel.price];
    
    self.regionAreaTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %@㎡ | %@",houseCooperationModel.region,houseCooperationModel.regionDetail,[PublicUtil returnTwoDeciTwoDecimalFormatter:houseCooperationModel.area],houseCooperationModel.houseType];
    
//    if (houseCooperationModel.read == 1) {
//        self.neighbourhoodAndPriceLabel.textColor = [UIColor grayColor];
//        self.regionAreaTypeLabel.textColor = [UIColor grayColor];
//    }
    
    if (houseCooperationModel.listTag.count > 0) {
        self.labelsViewHeight.constant = 30;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    
    for (UILabel *label in self.markLabels) {
        
        label.hidden = YES;
    }
    for (int i = 0; i < houseCooperationModel.listTag.count; i++) {
        UILabel *label = self.markLabels[i];
        if ([houseCooperationModel.listTag[i].tag isEqualToString:@""]) continue;
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",houseCooperationModel.listTag[i].tag];
        NSInteger colorIndex = houseCooperationModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
}



- (void)setIsHideButton:(BOOL)isHideButton {
    _isHideButton = isHideButton;
    self.recommendButton.hidden = isHideButton;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.visibleLabel.hidden = YES;
    self.visibleLabel.text = @"";
    
    self.recommendButton.hidden = self.isHideButton;
    
    // 设置推荐按钮的属性
    self.recommendButton.layer.borderWidth = 1;
    self.recommendButton.layer.borderColor = COLOR(0x33A3BB).CGColor;
    self.recommendButton.layer.cornerRadius = 4;
    self.recommendButton.layer.masksToBounds = YES;
    [self.recommendButton setTitleColor:MAIN_COLOR forState:UIControlStateNormal];
    [self.recommendButton setBackgroundImage:[ImageWithColor imageWithColor:[UIColor whiteColor]] forState: UIControlStateNormal];
    [self.recommendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self.recommendButton setBackgroundImage:[ImageWithColor imageWithColor:MAIN_COLOR] forState: UIControlStateHighlighted];

    for (UILabel *label in self.markLabels) {
        
        label.hidden = YES;
    }
    self.labelsViewHeight.constant = 1;
}





- (void)setButtonTitle:(NSString *)buttonTitle {
    _buttonTitle = buttonTitle;
    
    [self.recommendButton setTitle:buttonTitle forState:UIControlStateNormal];
}

/**
 点击推荐房源按钮
 */
- (IBAction)recommendButtonClick:(UIButton *)sender {
    
    // 送出代理
    if ([self.delegate respondsToSelector:@selector(housingCellRecommendButtonDidClick:)]) {
        
        [self.delegate housingCellRecommendButtonDidClick:sender];
    }
}




@end
